package com.huicheng;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.huicheng.ui.Ble_Activity;
import com.huicheng.utils.SharedPreUtils;

/**
 * Created by lk on 2018/3/3.
 */

public class SiginActivity extends Activity {
    private EditText name_edit;
    private EditText phone_edit;
    private Button sigin_button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sigin_layout);
        init();
    }
    private void init(){
        name_edit = (EditText) findViewById(R.id.name_edit);
        phone_edit = (EditText) findViewById(R.id.phone_edit);

        String name = SharedPreUtils.getInstance().getString("name");
        String phone = SharedPreUtils.getInstance().getString("phone");

        if (!TextUtils.isEmpty(name)){
            name_edit.setText(name);
        }

        if (!TextUtils.isEmpty(phone)){
            phone_edit.setText(phone);
        }

        sigin_button = (Button) findViewById(R.id.sigin_button);
        sigin_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String name = name_edit.getText().toString().trim();
                String phone = phone_edit.getText().toString().trim();
                if (TextUtils.isEmpty(name) || TextUtils.isEmpty(phone)){
                    Toast.makeText(SiginActivity.this,"姓名或手机号不能为空",Toast.LENGTH_LONG).show();
                }else {
                    SharedPreUtils.getInstance().putSting("name",name);
                    SharedPreUtils.getInstance().putSting("phone",phone);
                    Intent intent = new Intent(SiginActivity.this,MainActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    SiginActivity.this.startActivity(intent);
                }

            }
        });
    }
}
